<?php

namespace app\admin\controller;

use app\Base;
use app\service\ChatServices;
use Exception;
use think\response\Json;
use think\response\View;

/**
 * 聊天测试
 *
 * user ：Du
 * Date : 2022/3/26
 * Time : 14:34
 * Class Chat
 * @package projects\controller\admin
 */
class Chat extends Base
{

    /**
     * 聊天页面
     *
     * User : Du
     * Date : 2022/3/26
     * Time : 14:35
     * @return View
     */
    public function index(): View
    {
        $userId = session('manage_info')['id'];
        return view('admin/chat/index', ['userId' => $userId]);
    }

    /**
     * 用户发言
     *
     * User : Du
     * Date : 2022/3/26
     * Time : 14:49
     * @param ChatServices $services
     * @return Json
     * @throws Exception
     */
    public function sendMsg(ChatServices $services): Json
    {
        $res = $services::sendMessage(input());
        if (!$res) {
            return $this->returnData('fail', '发送失败');
        }
        return $this->returnData();
    }

    /**
     * 正在输入
     *
     * User : Du
     * Date : 2022/3/26
     * Time : 16:58
     * @param ChatServices $services
     * @return Json
     * @throws Exception
     */
    public function inputting(ChatServices $services): Json
    {
        $res = $services::inputStatus('inputting');
        return $this->returnData();
    }

    /**
     * 取消输入
     *
     * User : Du
     * Date : 2022/3/26
     * Time : 16:59
     * @param ChatServices $services
     * @return Json
     * @throws Exception
     */
    public function cancelInput(ChatServices $services): Json
    {
        $res = $services::inputStatus('cancelInput');
        return $this->returnData();
    }
}